# only works with the Java extension of yacc: 
# byacc/j from http://troi.lincom-asg.com/~rjamison/byacc/

BINDIR = ../../bin

include ../../Makefile.common

PACKAGE = frontend
LEXSRC = DayTrader.lex
YACCSRC = DayTrader.y

CWD = $(PWD)

# testsuites
testsuite: testcases
	$(JAVAC) -d $(BINDIR) test/TestSuite*.java

testcases: test/*Test.java frontend
	python test/genScannerTestCases.py -o test $(LEXSRC)
	$(JAVAC) -d $(BINDIR) test/*Test.java

# targets:
frontend: common $(BINDIR)/frontend/Parser.class
	$(JAVAC) -d $(BINDIR) *.java

$(BINDIR)/frontend/Parser.class: common Lexer.java Parser.java SyntaxTreeNode.java CompileError.java CompileErrors.java
	$(JAVAC) -d $(BINDIR) Lexer.java Parser.java SyntaxTreeNode.java CompileError.java CompileErrors.java

common:
	$(JAVAC) -d $(BINDIR) ../daytrader/common/*.java ../daytrader/lib/*.java ../daytrader/data/*.java ../daytrader/types/*.java

Lexer.java: $(LEXSRC)
	$(JFLEX) $(LEXSRC)

Parser.java: $(YACCSRC)
	$(BYACCJ) $(YACCSRC)

.PHONY: clean run test common

clean:
	rm -rf $(BINDIR)/$(PACKAGE) y.output

test: testsuite
	cd $(BINDIR) && java org.junit.runner.JUnitCore $(PACKAGE).test.TestSuiteScanner
	cd $(BINDIR) && java org.junit.runner.JUnitCore $(PACKAGE).test.TestSuiteScannerKeywords
